import { defHttp } from '/@/utils/http/axios'
import { PageResult } from '../model/baseModel'
import { ContentTypeEnum } from '/@/enums/httpEnum'

enum Api {
  Page = '/sysRole/page',
  Add = '/sysRole/add',
  Update = '/sysRole/updatePermissionAndMenu',
  UpdateUserRole = '/sysRole/updateUserRole',
  All = '/sysRole/all',
  UserRole = '/sysRole/userRole',
}

export const page = (param) => {
  return defHttp.get<PageResult<any>>({ url: Api.Page, params: param }, { urlPrefix: '/user' })
}

export const add = (param) => {
  return defHttp.post<null>(
    { url: Api.Add, params: param },
    { urlPrefix: '/user', errorMessageMode: 'modal', successMessage: 'message' },
  )
}

export const update = (param) => {
  return defHttp.post<null>(
    {
      url: Api.Update,
      params: param,
      headers: {
        'Content-Type': ContentTypeEnum.JSON,
      },
    },
    { urlPrefix: '/user', errorMessageMode: 'modal', successMessage: 'message' },
  )
}

export const updateUserRole = (param) => {
  return defHttp.post<null>(
    {
      url: Api.UpdateUserRole,
      params: param,
      headers: {
        'Content-Type': ContentTypeEnum.JSON,
      },
    },
    { urlPrefix: '/user', errorMessageMode: 'modal', successMessage: 'message' },
  )
}

export const all = () => {
  return defHttp.get<any>({ url: Api.All }, { urlPrefix: '/user' })
}

export const userRole = (userId) => {
  return defHttp.get<any>({ url: Api.UserRole, params: { userId } }, { urlPrefix: '/user' })
}
